<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>login</title>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../css/style.css">
    <!--    引入vue.js-->
    <script type="text/javascript" src="../js/vue.js"></script>
    <!--    引入axios.js-->
    <script type="text/javascript" src="../js/axios.js"></script>
</head>
<body>
<div id="app" style="height:350px">
    <el-form action="/brand-case/loginServlet" method="post" id="form">
        <h1 id="loginMsg">LOGIN IN</h1>
        <div id="errorMsg">{{loginMsg}} {{registerMsg}}</div>
        <table>
            <tr>
                <td>
                    登录名:
                </td>
                <td class="inputs">
                    <el-input v-model="username" placeholder="请输入用户名"></el-input>
                    <br>
                </td>
            </tr>
            <tr>
                <td>
                    密码:
                </td>
                <td class="inputs">
                    <el-input v-model="password" type="password" placeholder="请输入密码"></el-input>
                    <br>
                </td>
            </tr>
            <tr>
                <td class="inputs">
                    <el-checkbox v-model="checked">记住我</el-checkbox>
                </td>
            </tr>
        </table>
        <div id="subDiv">
            <el-button @click="login()">登录</el-button>
            <el-button>重置</el-button>
            <a href="register.html">没有账号？</a>
        </div>
    </el-form>
</div>
</body>
<style>
    * {
        margin: 0;
        botton: 0;
    }

    body {
        width: 100%;
        height: 100%;
        overflow: hidden;
    }

    #app {
        position: relative;
        width: 100%;
        height: 100%;
    }

    #form {
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, 0);
        display: block;
    }

    #form #subDiv {
        position: absolute;
        display: inline-block;
        right: 0;
    }

    /*.inputs .el-checkbox {*/
    /*    position: absolute;*/
    /*    right: 20px;*/
    /*    height: 40px;*/
    /*}*/
</style>
<!-- 引入组件库 -->
<script type="text/javascript" src="../js/index.js"></script>
<script>
    var vm = new Vue({
        el: "#app",
        methods: {
            login() {
                var params = new URLSearchParams()
                params.append("username", this.username)
                params.append("password", this.password)
                params.append("value", this.checked ? "1" : "0")
                axios({
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded',
                    },
                    data: params,
                    method: 'post',
                    url: 'http://localhost:8080/users/login'
                }).then(function (response) {
                    console.log(response);
                    console.log(response.data.msg)
                    this.loginMsg = response.data.msg
                    window.location.href = "./index.html"
                }).catch(function (error) {
                    console.log(error);
                });
            }
        },
        updated() {
        },
        data() {
            return {
                username: '',
                password: '',
                // value: '',
                loginMsg: '',
                registerMsg: '',
                checked: false
            }
        },

    })
</script>
</html>